package com.wxg.demo;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

import com.wxg.utils.My;
import com.wxg.utils.MyDriver;
import com.wxg.utils.MyFileWriter;

/**
 * 
 * 1) 将html切割成head,body
 * 2) 存储到另一个位置
 * 
 * 
 * @author Wxg
 *
 */
public class HtmlSplit101 {
	
	public static void main(String[] args) {
		code103();
	}
	
	
	public static void code103(){
		
		// webdriver
		WebDriver driver = MyDriver.getStaticDriver();
		String strUrl = My.fileUrl("F:\\wxg\\for_print\\html\\html104.html");
		driver.get( strUrl );
		
		// writer
		String dir = My.conf("htmlStoreDir");
		String filepath = dir + My.SP + My.ss("html_") + ".html";
		MyFileWriter writer = new MyFileWriter(filepath);
		
		writer.writeb("<html>");
		
		// head
		WebElement headEle = driver.findElement(By.tagName("head"));
		writer.writeb( headEle.getAttribute("outerHTML") );
		
		// body
		writer.writeb("<body>");
		
		writer.writeb("<h1>Hello,World!</h1>");
		
		writer.writeb("</body>");
		
		writer.writeb("</html>");
		
		// writer close
		writer.close();
		
		// driver quit
		MyDriver.closeStaticDriver();
	}
	
	
	public static void code102(){
		String dir = My.conf("htmlStoreDir");
		String filepath = dir + My.SP + My.ss("html_") + ".html";
		
		MyFileWriter writer = new MyFileWriter(filepath);
		writer.writeb("111");
		writer.writeb("222");
		writer.writeb("333");
		writer.close();
		
	}
	
	
	
	public static void code101(){
		WebDriver driver = MyDriver.getStaticDriver();
		
		String strUrl = My.fileUrl("F:\\wxg\\for_print\\html\\html104.html");
		
		driver.get( strUrl );
		
		WebElement headEle = driver.findElement(By.tagName("head"));
		System.out.println("===head===");
		System.out.println( headEle.getAttribute("outerHTML") );
		
		WebElement bodyEle = driver.findElement(By.tagName("body"));
		System.out.println("===body===");
		System.out.println( bodyEle.getAttribute("outerHTML") );
		
		MyDriver.closeStaticDriver();
		
	}
	
	
}
